
$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/sys/video/editVideo",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}else {
					window.location.href = "/";
				}
			}

		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			title : {
				required : true
			}
		},
		messages : {
			title : {
				required : icon + "视频类型不能为空"
			}
		},
		rules : {
			video_id : {
				required : true
			}
		},
		messages : {
			video_id : {
				required : icon + "视频类型不能为空"
			}
		},
		rules : {
			url : {
				required : true
			}
		},
		messages : {
			url : {
				required : icon + "请上传视频"
			}
		},
		rules : {
			explain : {
				required : true
			}
		},
		messages : {
			explain : {
				required : icon + "视频说明不能为空"
			}
		}
	})
}

function onThumbBlur() {
	var url = $.trim($('#thumb').val());
	if (url) {
		if (url.indexOf("http") >= 0 || url.indexOf("https") >= 0) {
			$('#categoryAddthumbImg').attr('src', url);
		}else {
			var prefix = "http://pic.jinzhishenghuo.com";
			$('#categoryAddthumbImg').attr('src', prefix + url);
		}
	}
}

/**
 * 选择视频页面
 * @param inputId
 * @param imgId
 */
function onSelectImgBtnClick(inputId, imgId) {
	layer.open({
		id:'selectImg',
		type : 2,
		title : '选择视频',
		maxmin : true,
		shadeClose : false,
		area : [ '90%', '90%' ],
		content : '/platform/config/selectVideo/' + inputId +"/"+ imgId // iframe的url
	});
}

/**
 * 加载图片URL
 * @param inputId
 * @param imgId
 * @param url
 */
function loadImgUrl(inputId, imgId, url) {
	$('#'+inputId +'').val(url);
	//$('#'+imgId +'').attr('src', url);
}